<template>
  <div id="app" v-if="isShow">
    <h2>测试题</h2>
    <subject
      v-for="(item, index) in arr"
      :key="index"
      :index="index"
      @result="resultFn"
      ref="mySubject"
    ></subject>
    <div>
      <flag
        v-for="(item, index) in arr"
        :key="index"
        :index="index"
        :list="item"
      ></flag>
      <div class="box">
        <button @click="btnFn">刷新题库</button>
      </div>
    </div>
  </div>
</template>

<script>
import subject from "./components/作业2/Subject";
import flag from "./components/作业2/Flag";

export default {
  // 注册组件
  components: {
    subject,
    flag,
  },
  created() {
    console.log(this);
    console.log(window);
  },
  data() {
    return {
      arr: ["未完成", "未完成", "未完成", "未完成", "未完成"],
      isShow: true,
    };
  },
  methods: {
    resultFn(resultStr, index) {
      // 把结果更新到数组 $set是vue内置方法
      // this.$set(目标数组,索引,要更新的结果))
      this.$set(this.arr, index, resultStr);
    },
    btnFn() {
      this.isShow = false;
      this.$nextTick(function () {
        this.isShow = true;
      });
    },
  },
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
.box {
  margin-top: 10px;
}
</style>